package com.tf_cut.backend.agent.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.tf_cut.backend.agent.service.AgentSellerRelationService;
import com.tf_cut.backend.agent.vo.AgentSellerRelationVo;
import com.tf_cut.backend.common.pojo.Result;


@RestController
@RequestMapping("/backend/agent/relation")
public class AgentSellerRelationController {
	
	@Autowired
	private AgentSellerRelationService agentSellerRelationService;
	
	// 关联代理商-商户，更新分润策略
	@RequestMapping("save")
    public String save(String json) {
		
		
		AgentSellerRelationVo avo = JSON.parseObject(json, AgentSellerRelationVo.class);
//		AgentSellerRelationVo avo = AgentSellerRelationVo.builder()
//				.agentId("1")
//				.sellerId("2")
//				.baseAmountPoint(7.5f)
//				.overAmountPoint(3.5f)
//				.serverAmountPoint(11.0f)
//				.stepAmountPoint(1.7f)
//				
//				.build();
		
		Result<AgentSellerRelationVo> result = agentSellerRelationService.save(avo);
        return JSON.toJSONString(result.getData());
    }
	
	// 查找代理商
	@RequestMapping("findListRelation")
	public String findListAgent(String json) {
//		json = "{\"agentId\":\"1\"}";
		AgentSellerRelationVo avo = JSON.parseObject(json, AgentSellerRelationVo.class);
		return JSON.toJSONString(agentSellerRelationService.findListRelation(avo).getData());
	}
}
